package com.example.study_thread.a_collection;

import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class Demo1Collection {
    public static void main(String[] args) {
        Collection<String> collection = new ArrayList();
        collection.add("a");
        collection.add("test");
        System.out.println(collection);

        Collection<String> collection1 = new ArrayList<>();
        collection1.add("张无忌");
        collection1.add("赵敏");

        collection1.addAll(collection);
        System.out.println(collection1);

//        清除集合中的所有元素
        collection1.clear();
        System.out.println(collection1);

//        是否包含某个元素
        boolean result = collection.contains("lihao");
        System.out.println("result:" + result);

//        集合是否为空
        boolean empty = collection1.isEmpty();
        System.out.println("是否为空：" + empty);

        collection.remove("test");
        System.out.println("剩余元素为：" + collection);

        int size = collection.size();
        System.out.println("集合大小为：" + size);

        collection.add("你好");
        collection.add("生活太不容易了");
//        将集合中的元素存储到数组中
        Object[] arr = collection.toArray();
        System.out.println("arr:" + arr);
        System.out.println(Arrays.toString(arr));


    }
}
